import moment from 'moment'
export const filterDataUtil = (sourceData = [], filterType = {
    unit: 's',
    value: 1
}) => {
    return sourceData.filter(item => {
        const theTime = moment(`${item['时间']}`, "YYYYMMDD HH:mm");
        let ruleValue = 0;
        switch (filterType.unit) {
            case 's':
                ruleValue = theTime.seconds();
                break;
            case 'm':
                ruleValue = theTime.minutes();
                break;
            case 'h':
                ruleValue = theTime.hours();
                break;
            default:
                ruleValue =0;
                break;
        }
        return ruleValue%filterType.value==0
    })
}


export const postDataFilter = (sourceData = {}) => {
    let list = []
    for(var i in sourceData){
        let thatMoment = moment(i,'YYYYMMDD-HHmmss');
        const lastobj = list[list.length-1]
        if(lastobj&&lastobj['时间']==thatMoment.format('YYYYMMDD HH:mm')){
            list.pop();
        }
        list.push({
            '时间':thatMoment.format('YYYYMMDD HH:mm'),
            '数值':sourceData[i].water
        })
    }
    return list
}